﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XQ.Framework.core
{
    public class StaticDataBase
    {
        public static readonly string[] imageExtesions = new string[] { ".jpg", ".png", ".gif", ".bmp", ".jpeg" };

        public static class System
        {
            public static Dictionary<string, string> getSysPage()
            {
                Dictionary<string, string> data = new Dictionary<string, string>() 
                {
                    {"about","关于我们"},
                    {"contact","联系方式"},
                    {"culture","公司文化"},
                };
                return data;
            }
            public static List<object> getSysPageObjectKeyList()
            {
                List<object> list = new List<object>();
                StaticDataBase.System.getSysPage().Keys.ToList().ForEach(delegate(string key)
                {
                    list.Add(key);
                });
                return list;
            }
            public static bool IsSysPage(string typename)
            {
                return getSysPage().Keys.Contains(ConvertHelper.getString(typename));
            }
            public static string getSysPageName(string typename)
            {
                typename = ConvertHelper.getString(typename);
                if (getSysPage().Keys.Contains(typename))
                {
                    return ConvertHelper.getString(getSysPage()[typename]);
                }
                return string.Empty;
            }
        }

        public static class HttpContentType
        {
            public static readonly string Html = "";
            public static readonly string Text = "";
            public static readonly string Xml = "";
            public static readonly string Json = "";
            public static readonly string Jpg = "";
            public static readonly string Jpeg = "";
            public static readonly string Gif = "";
            public static readonly string Png = "";
            public static readonly string Bmp = "";
        }

        public class OnlineCount
        {
            private static readonly object CountLock = new object();
            private static int Count = 0;
            public static void Online()
            {
                lock (CountLock)
                {
                    ++Count;
                    Count = Count < 0 ? 0 : Count;
                }
            }
            public static void Offline()
            {
                lock (CountLock)
                {
                    --Count;
                    Count = Count < 0 ? 0 : Count;
                }
            }
            public static int GetCount() { return Count; }
        }

        public static class Time
        {
            #region 服务器开启时间
            private static DateTime ServerStartTime = DateTime.Now;
            private static readonly object SERVICE_TIME_LOCK = new object();
            public static TimeSpan GetServiceTimeCount()
            {
                if (ServerStartTime == null)
                {
                    lock (SERVICE_TIME_LOCK)
                    {
                        if (ServerStartTime == null)
                        {
                            ServerStartTime = DateTime.Now;
                        }
                    }
                }
                return (DateTime.Now - ServerStartTime);
            }
            #endregion
        }

        public class ErrorValue
        {
            public static readonly int ERROR_INT = int.MinValue;
            public static readonly string ERROR_STRING = "16165464531561412419243516541635216587465168796163546854";
        }

    }
}
